﻿//=======================================================
// Author: Jonas Follesø <jonas@follesoe.no>
// Copyright (c) 2008
//
// Licensed under the Microsoft Public License (Ms-PL)
// A copy of the license is available at 
// http://www.opensource.org/licenses/ms-pl.html
//=======================================================

using System;
using System.Collections.Generic;
using System.Windows.Media;
using System.ComponentModel;

namespace Colorful.Control
{
    public class Palette : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public int Id { get; set; }
        public int Rating { get; set; }
        public int Downloads { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public string Author { get; set; }
        public string ThemeUrl { get; set; }
        public DateTime CreatedAt { get; set; }

        public Color Color1 { get; set; }
        public Color Color2 { get; set; }
        public Color Color3 { get; set; }
        public Color Color4 { get; set; }
        public Color Color5 { get; set; }

        public IEnumerable<Color> ColorList
        {
            get
            {
                yield return Color1;
                yield return Color2;
                yield return Color3;
                yield return Color4;
                yield return Color5;
            }
            set
            {
                var colorList = new List<Color>(value);
                Color1 = colorList.Count > 0 ? colorList[0] : Colors.White;
                Color2 = colorList.Count > 1 ? colorList[1] : Colors.White;
                Color3 = colorList.Count > 2 ? colorList[2] : Colors.White;
                Color4 = colorList.Count > 3 ? colorList[3] : Colors.White;
                Color5 = colorList.Count > 4 ? colorList[4] : Colors.White;
            }
        }

        public Palette()
        {
            Color1 = Colors.White;
            Color2 = Colors.White;
            Color3 = Colors.White;
            Color4 = Colors.White;
            Color5 = Colors.White;
        }

        private void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}